package com.xpxrule.controller.manage;

import com.xpxrule.dataobject.biz.model.ReturnResponse;
import com.xpxrule.dataobject.req.BusinessModelQueryReq;
import com.xpxrule.dataobject.vo.BusinessModelVo;
import com.xpxrule.dataobject.vo.FieldInfoVo;
import com.xpxrule.dataobject.vo.OptionVo;
import com.xpxrule.service.BusinessModelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @version 1.0
 * @Author xiangpengxiang
 * @Date 2024/11/20 19:31
 * @注释
 */
@RestController
@RequestMapping("/businessModel")
public class BusinessModelController {
    @Autowired
    private BusinessModelService businessModelService;

    /**
     * 新增业务模型
     * @param vo
     * @return
     */
    @PostMapping("/insert")
    public ReturnResponse<Integer> insert(@RequestBody BusinessModelVo vo){
        return businessModelService.insert(vo);
    }

    /**
     * 根据id删除业务模型
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    public ReturnResponse<Integer> delete(@PathVariable("id") Long id){
        return businessModelService.delete(id);
    }

    /**
     * 根据id更新业务模型
     * @param vo
     * @return
     */
    @PostMapping("/update")
    public ReturnResponse<Integer> update(@RequestBody BusinessModelVo vo) {
        return businessModelService. update(vo);
    }

    /**
     * 根据查询条件查询业务模型
     * @param req
     * @return
     */
    @PostMapping("/select/byQuery")
    public ReturnResponse<List<BusinessModelVo>> selectList(@RequestBody BusinessModelQueryReq req) {
        return businessModelService.selectList(req);
    }

    /**
     * 获取所以自定义类型下拉选项
     * @return
     */
    @GetMapping("/get/all/businessModel/options")
    public ReturnResponse<List<OptionVo>> getAllBusinessModelOptions() {
        return businessModelService.getAllBusinessModelOptions();
    }

    /**
     * 根据业务模型获取所有字段列表
     * @return
     */
    @GetMapping("/get/fieldList/by/{modelKey}")
    public ReturnResponse<List<FieldInfoVo>> getFieldListByBusinessModelKey(@PathVariable("modelKey") String modelKey) {
        return businessModelService.getFieldListByBusinessModelKey(modelKey);
    }
}
